package com.tarena.lbs.basic.web.ex.handler;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


// controller的切面 通知类型是异常通知
@RestControllerAdvice("com.tarena.lbs.basic.web.controller")
@Slf4j
public class GlobalExcepiontHandler {
    //1.BusinessException 业务异常 code message
    @ExceptionHandler(BusinessException.class)
    public Result handleBiz(BusinessException e){
        //从异常后去code和message 封装result
        log.error("出现业务异常");
        return Result.fail(e);
    }
    //2.Throwable 系统异常
    @ExceptionHandler(Throwable.class)
    public Result handleThrowable(Throwable e){
        //提示 系统异常 system error
        log.error("出现系统异常",e);
        return Result.fail();
    }
    //spring-boot-starter-validation 校验异常2MethodArgumentException BindingException
}
